package ru.MatrosovaNastya;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import  java.io.BufferedReader;
import  java.io.FileReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        LinkedDeque my_deque = new LinkedDeque();
        try (
                BufferedReader in = new BufferedReader(new FileReader("command.txt"));
                PrintWriter write = new PrintWriter("out.txt")
        ) {
            String str;
            String command;
            Integer number=0;
                while ((str = in.readLine()) != null) {
                    StringTokenizer st = new StringTokenizer(str);
                    command = st.nextToken();
                        if (st.hasMoreTokens()) {
                            number = Integer.parseInt(st.nextToken());
                        }
                        if (command.equals("size")) {
                            write.print("Command Size: ");
                            write.print(my_deque.size());
                            write.print("\n");
                        }
                        if (command.equals("clear")) {
                            write.print("Command Clear: ");
                            my_deque.clear();
                            if (my_deque.isEmpty() == true) {
                                write.print("Your Deque is clear ");
                            }
                            write.print("\n");
                        }
                        if (command.equals("isEmpty")) {
                            write.print("Command isEmpty: ");
                            if (my_deque.isEmpty() == true) {
                                write.print("Your Deque is Empty");
                            }
                            write.print("\n");
                        }
                        if (command.equals("toString")) {
                            write.print("Command toString: ");
                            write.print(my_deque.toString());
                            write.print("\n");

                        }
                        if (command.equals("addFirst")) {
                            write.print("Command addFirst: ");
                            my_deque.addFirst(number);
                            write.print(my_deque);
                            write.print("\n");
                        }
                        if (command.equals("addLast")) {
                            write.print("Command addLast: ");
                            my_deque.addLast(number);
                            write.print(my_deque);
                            write.print("\n");
                        }
                        if (command.equals("pollFirst")) {
                            write.print("Command pollFirst: ");
                            write.print(my_deque.pollFirst());
                            write.print(my_deque);
                            write.print("\n");
                        }
                        if (command.equals("pollLast")) {
                            write.print("Command pollLast: ");
                            write.print(my_deque.pollLast());
                            write.print(my_deque);
                            write.print("\n");
                        }
                        if (command.equals("getFirst")) {
                            write.print("Command getFirst: ");
                            write.print(my_deque.getFirst());
                            write.print("\n");
                        }
                        if (command.equals("getLast")) {
                            write.print("Command getLast: ");
                            write.print(my_deque.getLast());
                            write.print("\n");
                        }
                        if (command.equals("peekFirst")) {
                            write.print("Command peekFirst: ");
                            write.print(my_deque.peekFirst());
                            write.print("\n");
                        }
                        if (command.equals("peekLast")) {
                            write.print("Command peekLast: ");
                            write.print(my_deque.peekLast());
                            write.print("\n");
                        }

                }
            write.close();
        } catch (IOException e) {
            System.err.println(e);
        }


    }
}
